package javaapplication8.Make;

// $Source: /h/u1/szamosi/repo/b07/examples/remake/MakeRule.java,v $
// $Date: 2007/06/24 00:25:13 $
// $Revision: 1.1.1.1 $

import java.util.Iterator;

class MakeRule extends SimpleRule {

    // Construct an empty rule
    public MakeRule() {
        super();
        init();
    }
  
    // Construct a new rule with the specified target, pre-requisites,
    // and actions
    public MakeRule(String target, String[] prereqs, String[] actions) {
        super(target, prereqs, actions);
        init();
    }
  
    // Execute this rule's actions unless that has already been done
    public void execute() {
        if (!fExecuted) {
            System.out.println("Executing rules for " + this.getTarget());
            Iterator ia = this.getActionIter();
            if (!ia.hasNext()) {
                System.out.println("\t<no rules>");
            }
            else {
                while (ia.hasNext()) {
                    System.out.println("\t" + (String)ia.next());
                }
            }
            fExecuted = true;
        }
    }
  
    // Has this target been changed?
    public boolean isChanged() {
        return fChanged;
    }

    // Set or clear this rule's changed flag
    public void setChanged(boolean changed) {
        fChanged = changed;
    }

    // Have this rule's actions been executed?
    public boolean isExecuted() {
        return fExecuted;
    }

    // Set this rule's executed flag
    public void setExecuted(boolean executed) {
        fExecuted = executed;
    }
  
    // Convert to printable form
    public String toString() {
        String result = super.toString();
        result += "\n.\tchanged: " + fChanged;
        result += "\n.\texecuted: " + fExecuted;
        return result;
    }
  
    //------------------------------------------------------------

    // Common initialization
    protected void init() {
        fChanged = false;
        fExecuted = false;
    }
  
    protected boolean   fChanged;       // Has this target changed?
    protected boolean   fExecuted;      // Have actions been executed?
}
